home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / editor / tagcase0.zip / TAGCASE.C < prev    next >
C/C++ Source or Header  |  1997-03-20  |  1KB  |  69 lines

  1. /**************************************
  2.  * TAGCASE.C - ANSI.C
  3.  *
  4.  * Text filter to convert HTML tags to uppercase
  5.  * preserving the contents of quoted things
  6.  *
  7.  * Use: TAGCASE +|- < inputfile [>outputfile]
  8.  *
  9.  * NOTES: 1. Comments will be converted
  10.  *        2. You're on your own about this code, and so am I.
  11.  *
  12.  * Joao C de Magalhaes, 1997-03-19
  13.  * jcm@individual.EUnet.pt
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include <ctype.h>
  18.  
  19. int main(int argc, char ** argv)
  20.    {
  21.    int Opt, C, InBracket, Convert;
  22.  
  23.    if (argc != 2)
  24.       {
  25.       puts("Converts the case of HTML tags.");
  26.       puts("Comments will also be converted, "
  27.     "but not attribute values.");
  28.       puts("Use as a filter. Basic syntax is:");
  29.       puts("TAGCASE +|- < infile [>outfile]");
  30.       puts("\t+ converts tags to upper case");
  31.       puts("\t- converts tags to lower case");
  32.       return(1);
  33.       }
  34.  
  35.    Opt = *argv[1];
  36.  
  37.    if (Opt == '-') Opt = 1;
  38.    else Opt = 0;
  39.  
  40.    C = InBracket = Convert = 0;
  41.  
  42.    while((C=getchar()) != EOF)
  43.       {
  44.       if (C == '<')
  45.      {
  46.      InBracket = 1;
  47.      Convert = 1;
  48.      }
  49.       if (C == '>')
  50.      {
  51.      InBracket = 0;
  52.      Convert = 0;
  53.      }
  54.       if (InBracket)
  55.      {
  56.      if (C == '\"')
  57.         if (Convert) Convert = 0;
  58.         else Convert =1;
  59.      }
  60.       if (Convert)
  61.      {
  62.      if (Opt == 1) putchar(tolower(C));
  63.      else putchar(toupper(C));
  64.      }
  65.       else putchar(C);
  66.       }
  67.    return 0;
  68.    }
  69.